

//选择框选中取消
$(".all_check").on("click",function(){
	if($(this).hasClass("checked")){
		$(this).removeClass("checked");
		for(var i=0;i<$(".single_check").length;i++){
			$(".single_check").eq(i).removeClass("checked");
		}
	}else{
		$(this).addClass("checked");
		for(var i=0;i<$(".single_check").length;i++){
			$(".single_check").eq(i).addClass("checked");
		}
	}
})

//切换状态
$(".list_state").on("click",function(){
	$(".state_type").attr("data",$(this).attr("data"));
	$(".state_type").html($(this).html());
	p=1;
	tiaozhuan(p);
})

//创意审核报表接口
var p=1;
function tiaozhuan(p){
	var pageSize=$('.ui-select-pagesize').val();
	var materialName=$(".materialName").val();
	var state=$(".state_type").attr("data");
	var d={};
	d.pageSize=pageSize;
	d.materialName=materialName;
	d.page=p;
	d.state=state;
	$.ajax({
		url: url + "/sys/adOrderOri/queryPage",
		type: 'POST',
		//		参数需转为字符串
		data: JSON.stringify(d),
		//		json跨域
		dataType: 'json',
		contentType: "application/json",
		beforeSend: function(XMLHttpRequest) {
			XMLHttpRequest.setRequestHeader("X-Token", token); 
		},
		useDefaultXhrHeader: false,
		success: function(result) {
			if(result.code == '0') {
				var data=result.data.rows;
				var html="";
				for(var i in data){
					html += '<tr class="ng-scope"><td class="ng-scope">';
					html += '<div class="check ng-isolate-scope single_check" data="'+data[i].id+'"><b></b></div></td>';
					html += '<td><div class="material-cover ng-scope" style="background-image: url('+data[i].photoUrl+');">';
					html += '<div class="material-cover-mask kk_a" data="'+data[i].photoUrl+'"></div>';
					html += '</div></td><td class="l20"><div class="ng-binding">广告公司名称：'+data[i].adComName+'</div>';
					html += '<div class="ng-binding">广告主名称：'+data[i].adOwnerName+'</div></div>';
					html += '</td><td class="l20"><p class="ng-binding">创意名称：'+data[i].originalityName+'</p>';
					html += '<p class="ng-binding">创意ID：106964</p>';
//					创意类型
					if(data[i].originalityType == "0"){
						html += '<p class="ng-binding">行业分类：视频</p>';
					}else if(data[i].originalityType == "1"){
						html += '<p class="ng-binding">行业分类：H5</p>';
					}else if(data[i].originalityType == "2"){
						html += '<p class="ng-binding">行业分类：文字链</p>';
					}else if(data[i].originalityType == "3"){
						html += '<p class="ng-binding">行业分类：单图</p>';
					}else if(data[i].originalityType == "4"){
						html += '<p class="ng-binding">行业分类：原生</p>';
					}
					
//					创意广告位类型判断
					if(data[i].originalityAdType == "0"){
						html += '<p class="ng-binding">广告位类型：开屏</p>';
					}else if(data[i].originalityAdType == "1"){
						html += '<p class="ng-binding">广告位类型：插屏幕</p>';
					}else if(data[i].originalityAdType == "2"){
						html += '<p class="ng-binding">广告位类型：Banner</p>';
					}else if(data[i].originalityAdType == "2"){
						html += '<p class="ng-binding">广告位类型：原生</p>';
					}
					html += '</td><td class="l20"><div class="ng-scope"><div class="ng-scope">';
					html += '<span>图片：</span><a href="javascript:;" data="'+data[i].photoUrl+'" class="ng-binding kk_a">'+data[i].photoUrl+'</a>';
					html += '</div></div><div class="ng-binding">点击监测：'+data[i].clickMonitor+'<br> 曝光监测：'+data[i].exposureMonitor+'<br>';
					html += '<div class="ng-scope">落地页：<a target="_blank" class="ng-binding" href="'+data[i].squeezePage+'">'+data[i].squeezePage+'</a>';
					html += '</div></div></td><td class="btns"><span class="audit audit-orange">';
//					审核状态
					if(data[i].state == 0){
						html += '内审状态<span class="audit-text ng-binding">待审核</span></span></td><td class="ng-scope">';
					}else if(data[i].state == 1){
						html += '内审状态<span class="audit-text ng-binding">审核通过</span></span></td><td class="ng-scope">';
					}else if(data[i].state == 2){
						html += '内审状态<span class="audit-text ng-binding">审核拒绝</span></span></td><td class="ng-scope">';
					}
					
//					第一个通过不通过,第二个id,第三个单个或所有
					html += '<button class="dsp-btn btn-green ng-scope" onclick="auditCretive(1,'+data[i].id+',1)">通过</button>';
					html += '<button class="dsp-btn btn-red ng-scope" onclick="auditCretive(2,'+data[i].id+',1)">拒绝</button></td></tr>';
				}
				$(".creative_list").html(html);
				var r=result.data.total;
					paging(p,pageSize,r);
//				打开图片
				$(".kk_a").on("click",function(){
					showImg($(this).attr("data"));
				})
				
//				选中
				$(".single_check").on("click",function(){
					if($(this).hasClass("checked")){
						$(this).removeClass("checked");
					}else{
						$(this).addClass("checked");
					}
				})
			} else {
				isErr(result);
			}
		},
		err: function(err) {
			layer.msg("请求失败");
		}
	}); 
}
tiaozhuan(1);


//搜索按钮
$(".materialName_btn").on("click",function(){
	p=1;
	tiaozhuan(p);
})
function auditCretive(type,ids1,type_all) {
	var str = type == "1" ? "通过" : "拒绝";
	var ids=[];
	if(type_all == 0) {
		for(var i=0;i<$(".single_check").length;i++){
			if($(".single_check").eq(i).hasClass("checked")){
				ids.push($(".single_check").eq(i).attr("data"));
			}
		}
	}else{
		ids.push(ids1);
	}
	if(ids.length == 0) return layer.msg("请先选择素材!")
	layer.confirm('是否确定' + str + '？', {
		btn: ['确定', '取消'] //按钮
	},function(){
		var d={};
		d.ids=ids;
		d.state=type;
		$.ajax({
			url: url + "/sys/adOrderOri/check",
			type: 'POST',
			//		参数需转为字符串
			data: JSON.stringify(d),
			//		json跨域
			dataType: 'json',
			contentType: "application/json",
			beforeSend: function(XMLHttpRequest) {
				XMLHttpRequest.setRequestHeader("X-Token", token); 
			},
			useDefaultXhrHeader: false,
			success: function(result) {
				if(result.code == '0') {
					layer.msg(result.msg,{time:2*1000},function() {
						p=1;
						tiaozhuan(p);
					});
				} else {
					isErr(result);
				}
			},
			err: function(err) {
				layer.msg("请求失败");
			}
		}); 
	});
}